1 module hip.view.load_scene;
2 import hip.view.scene;
3 import hip.api.view.scene;
4 import hip.graphics.g2d.renderer2d;
5 import hip.assetmanager;
6 
7 
8 private __gshared
9 {
10     HipColor fgColor = color(50, 200, 20);
11     HipColor bgColor = color(40,40,40);
12 
13 }
14 
15 class LoadingScene: AScene
16 {
17     mixin Preload;
18     int x, y;
19     private float percentage = 0;
20     private int width, height, borderSize;
21     int assetsToLoad;
22 
23     override void initialize()
24     {
25         Viewport vp = getCurrentViewport();
26         int[2] window = [vp.width, vp.height];
27         width = cast(int)(window[0] * 0.8);
28         height = cast(int)(window[1] / 8);
29         borderSize = cast(int)(window[0] * 0.05);
30         x = (window[0] / 2) - (width / 2);
31         y = (window[1] / 2) - (height / 2);
32 
33         assetsToLoad = HipAssetManager.getAssetsToLoadCount();
34     }
35 
36     override void update(float dt)
37     {
38         setPercentage(cast(float)(assetsToLoad - HipAssetManager.getAssetsToLoadCount()) / assetsToLoad);
39     }
40 
41     /** 
42      * Percentage must be a value between 0 and 1
43      */
44     void setPercentage(float percentage)
45     {
46         import hip.math.utils;
47         this.percentage = clamp(percentage, 0, 1);
48     }
49 
50     override void render()
51     {
52         fillRectangle(x, y, width, height, bgColor);
53 
54         int halfB = borderSize/2;
55         fillRectangle(x+halfB, y+halfB, cast(int)((width-borderSize)*percentage), (height - borderSize), fgColor);
56 
57         drawRectangle(x+halfB, y+halfB, (width-borderSize), (height - borderSize), fgColor);
58 
59         String s = String("Loaded: ", assetsToLoad - HipAssetManager.getAssetsToLoadCount(), "/", assetsToLoad);
60         drawText(s.toString, x, y, 1, HipColor.yellow, HipTextAlign.topCenter, Size(width, height));
61 
62 
63     }
64 
65     override void onResize(uint width, uint height){}
66     override void dispose(){}
67 }